<?php

namespace App\Biz;

use App\Models\Config;
use App\Models\Reserves;
use App\Models\Visitor;
use App\Models\VisitorReservesLog;

class VisitorReservesLogBiz extends BaseBiz
{

    public function __construct(VisitorReservesLog $visitorReservesLog)
    {
        $this->model = $visitorReservesLog;
    }

    /**
     * 创建访问预约日志
     * @param Config $config
     * @param Reserves $reserves
     * @param Visitor $visitor
     * @return bool
     */
    public function create(Config $config, Reserves $reserves, Visitor $visitor): bool
    {
        $this->model->visitor_reserves_id        = $reserves->id;
        $this->model->visitor_id                 = $visitor->id;
        $this->model->interviewee_information_id = $reserves->interviewee_information_id;
        $this->model->reason                     = $reserves->reason;
        $this->model->device_groups              = $reserves->device_groups;
        $this->model->source                     = $reserves->source;
        $this->model->start_time                 = $reserves->start_time;
        $this->model->end_time                   = $reserves->end_time;
        $this->model->interviewee_name           = $reserves->intervieweeInformation->name;
        $this->model->interviewee_phone          = $reserves->intervieweeInformation->phone;
        $this->model->interviewee_openId         = $reserves->intervieweeInformation->openId;
        $this->model->visitor_name               = $visitor->visitorName;
        $this->model->visitor_telephone          = $visitor->telephone;
        $this->model->visitor_openId             = $visitor->openId;
        $this->model->appId                      = $config->appId;
        $this->model->authorId                   = $config->authorId;
        $this->model->captcha                    = $config->captcha ?? '';
        $this->model->passType                   = $config->passType;
        $this->model->peers                      = $config->peers;
        return $this->model->save();
    }
}
